package com.study.flink.source

import org.apache.flink.streaming.api.scala.{DataStream, StreamExecutionEnvironment}

/**
  * Collection Source Demo
  *
  * @author stephen
  * @date 2019-07-22 14:28
  */
object ScalaCollectionSourceDemo {

  def main(args: Array[String]): Unit = {
    // 1 获取执行环境
    val env = StreamExecutionEnvironment.getExecutionEnvironment

    // 2 获取数据
    import org.apache.flink.api.scala._
    val text: DataStream[String] = env.fromCollection(List("a", "b", "c", "d"))
    //val text = env.fromElements("a","v","c","a")
    //val text = env.fromElements(Tuple2("a",1),Tuple2("b",2))
    //val text = env.fromElements(List("a","v","c","a"),List("a","v","c","a"))
    //val text = env.fromCollection(Array("a","v","c","a"))
    //val text = env.fromCollection(List("a","v","c","a"))

    // 3 transformation
    val wordCountStream = text.map((_,1)).keyBy(_._1).sum(1)

    // 4 输出
    wordCountStream.print()

    // 5 启动任务
    env.execute("Collection Source Demo")
  }
}
